package com.polytech.diploma.SQLGenerator.Oracle.Functions.AnalyticFunctions.WindowClause;

import java.util.List;
import java.util.Map;

import com.polytech.diploma.SQLGenerator.Oracle.Node;

public class WindowClause implements Node{
	protected ResultUnit resultUnit;
	protected WindowBound leftBound;
	protected WindowBound rightBound;
	
	private WindowClause(Builder builder)
	{
		this.resultUnit = builder.resultUnit;
		this.leftBound = builder.leftBound;
		this.rightBound = builder.rightBound;
	}
	
	public static class Builder{
		private ResultUnit resultUnit;
		private WindowBound leftBound;
		private WindowBound rightBound;
		
		public Builder setResultUnit(ResultUnit resultUnit) {
			this.resultUnit = resultUnit;
			return this;
		}
		public Builder setLeftBound(WindowBound leftBound) {
			this.leftBound = leftBound;
			return this;
		}
		public Builder setRightBound(WindowBound rightBound) {
			this.rightBound = rightBound;
			return this;
		}
		
		public WindowClause build()
		{
			return new WindowClause(this);
		}
	}

	public ResultUnit getResultUnit() {
		return resultUnit;
	}

	public WindowBound getLeftBound() {
		return leftBound;
	}

	public WindowBound getRightBound() {
		return rightBound;
	}

	@Override
	public Map<String, List<String>> getTablesWithFields(
			Map<String, List<String>> fieldMap) {
		if(leftBound != null)
			fieldMap = leftBound.getTablesWithFields(fieldMap);
		if(rightBound != null)
			fieldMap = rightBound.getTablesWithFields(fieldMap);
		return fieldMap;
	}
	
}
